var table = null;
layui
    .config({
        base: '../layui/exts/', //静态资源所在路径
    })
    .use(['table'], function () {
        lui = layui;
        $ = layui.$;

        //载入全宗信息
        table = layui.table;
        table.render({
            elem: '#codeFormatTable'
            , url: '../basic/getArchivesFormatCodeList?pid=' + pid
            , method: 'get'
            , cellMinWidth: 80
            , page: false
            , limit: 50
            , height: 'full-70'
            , loading: true
            , size: 'sm'
            , cols: [
                [ //标题栏
                    {field: 'title', title: '标题', width: 200},
                    {field: 'doc', title: '连接符'},
                    {field: 'len', title: '长度'},
                    {fixed: 'right', title: '操作', width: 80, toolbar: '#operationBar'}
                ]
            ]
        });

        //监听工具条
        table.on('tool(codeFormatTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                top.layer.open({
                    type: 2,
                    title: '编辑',
                    content: './basic/setArchivesCodeFormat?' +
                        '&classifyId=' + classifyId + '&pid=' + pid + '&id=' + data.id +
                        '&children=' + children + '&codeModel=' + codeModel,
                    area: ['420px', '330px'],
                    shadeClose: false,
                    resize: false,
                    btn: [
                        '<i class="layui-icon">&#xe605;</i> 确定',
                        '<i class="layui-icon">&#x1006;</i> 取消',
                    ],
                    yes: function (index, layero) {
                        var iframeWin = layero.find('iframe')[0];
                        if (iframeWin.contentWindow.Buttun_Submit()) {
                            table.reload('codeFormatTable');
                        }
                    },
                    btn2: function (index) {
                        layer.close(index); //如果设定了yes回调，需进行手工关闭
                    },
                });
            } else if (obj.event === 'del') {
                top.layer.confirm('确定要删除当前选择的档号结构吗？ ', function (index) {
                    $.ajax({
                        url: './delArchivesCodeFormatList', //url
                        dataType: 'json', //数据格式
                        type: 'POST', //请求方式
                        async: false, //是否异步请求
                        data: {id: data.id, pid: pid, classifyId: classifyId},
                        success: function (result) {
                            if (result.code == 0) {
                                table.reload('codeFormatTable');
                                layer.close(index);
                                top.parent.layer.msg(result.message, {icon: 1});
                            } else {
                                top.parent.layer.alert(result.message, {icon: 2});
                            }
                        },
                    });
                    return false;
                });
            }
        });

    });

//新增
function newCodeFormatData() {
    top.layer.open({
        type: 2,
        title: '新增',
        content: './basic/setArchivesCodeFormat?' +
            '&classifyId=' + classifyId + "&parentId=" + parentId +
            '&pid=' + pid + '&id=' + '&children=' + children +
            '&codeModel=' + codeModel,
        area: ['420px', '330px'],
        shadeClose: false,
        resize: false,
        btn: [
            '<i class="layui-icon">&#xe605;</i> 确定',
            '<i class="layui-icon">&#x1006;</i> 取消',
        ],
        yes: function (index, layero) {
            var iframeWin = layero.find('iframe')[0];
            if (iframeWin.contentWindow.Buttun_Submit()) {
                table.reload('codeFormatTable');
            }
        },
        btn2: function (index) {
            layer.close(index); //如果设定了yes回调，需进行手工关闭
        },
    });
}
